home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / cube.c < prev    next >
C/C++ Source or Header  |  1994-12-18  |  3KB  |  175 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #ifdef SGI
  5. #include "gl.h"
  6. #include "device.h"
  7. #include "hershey.h"
  8. #else
  9. #include "vogl.h"
  10. #include "vodevice.h"
  11. #endif
  12.  
  13. Coord carray[][3] = { -1.0,  -1.0,   1.0, /* front */
  14.               1.0,  -1.0,   1.0,
  15.               1.0,   1.0,   1.0,
  16.              -1.0,   1.0,   1.0,
  17.              -1.0,  -1.0,  -1.0, /* rear */
  18.               1.0,  -1.0,  -1.0,
  19.               1.0,   1.0,  -1.0,
  20.              -1.0,   1.0,  -1.0
  21.         };
  22.  
  23. int    nplanes;
  24.  
  25. /* ---------------------------------------------------------------------
  26.  * Prototypes:
  27.  */
  28. void drawcube(void);                                   /* cube.c          */
  29. int main( int, char **);                               /* cube.c          */
  30.  
  31. /* ---------------------------------------------------------------------
  32.  * Source Code:
  33.  */
  34.  
  35. /*
  36.  * drawcube
  37.  *
  38.  *    draw the cube setting colours if available
  39.  */
  40. void drawcube(void)
  41. {
  42.     if (nplanes > 1)
  43.         color(RED);
  44.  
  45.     /* Front */
  46.     pmv(carray[0][0], carray[0][1], carray[0][2]);
  47.     pdr(carray[1][0], carray[1][1], carray[1][2]);
  48.     pdr(carray[2][0], carray[2][1], carray[2][2]);
  49.     pdr(carray[3][0], carray[3][1], carray[3][2]);
  50.     pclos();
  51.     
  52.     if (nplanes > 1)
  53.         color(GREEN);
  54.  
  55.     /* Back */
  56.     pmv(carray[5][0], carray[5][1], carray[5][2]);
  57.     pdr(carray[4][0], carray[4][1], carray[4][2]);
  58.     pdr(carray[7][0], carray[7][1], carray[7][2]);
  59.     pdr(carray[6][0], carray[6][1], carray[6][2]);
  60.     pclos();
  61.  
  62.     if (nplanes > 1)
  63.         color(YELLOW);
  64.  
  65.     /* Right side */
  66.     pmv(carray[1][0], carray[1][1], carray[1][2]);
  67.     pdr(carray[5][0], carray[5][1], carray[5][2]);
  68.     pdr(carray[6][0], carray[6][1], carray[6][2]);
  69.     pdr(carray[2][0], carray[2][1], carray[2][2]);
  70.     pclos();
  71.  
  72.     if (nplanes > 1)
  73.         color(BLUE);
  74.  
  75.     /* Left side */
  76.     pmv(carray[0][0], carray[0][1], carray[0][2]);
  77.     pdr(carray[3][0], carray[3][1], carray[3][2]);
  78.     pdr(carray[7][0], carray[7][1], carray[7][2]);
  79.     pdr(carray[4][0], carray[4][1], carray[4][2]);
  80.     pclos();
  81.  
  82.     if (nplanes > 1)
  83.         color(MAGENTA);
  84.  
  85.     /* Top */
  86.     pmv(carray[2][0], carray[2][1], carray[2][2]);
  87.     pdr(carray[6][0], carray[6][1], carray[6][2]);
  88.     pdr(carray[7][0], carray[7][1], carray[7][2]);
  89.     pdr(carray[3][0], carray[3][1], carray[3][2]);
  90.     pclos();
  91.     
  92.     if (nplanes > 1)
  93.         color(CYAN);
  94.  
  95.     /* Bottom */
  96.     pmv(carray[0][0], carray[0][1], carray[0][2]);
  97.     pdr(carray[4][0], carray[4][1], carray[4][2]);
  98.     pdr(carray[5][0], carray[5][1], carray[5][2]);
  99.     pdr(carray[1][0], carray[1][1], carray[1][2]);
  100.     pclos();
  101. }
  102.  
  103.  
  104. int main(
  105.   int    argc,
  106.   char **argv)
  107. {
  108.     float    t, dt = 0.2;
  109.     int    r, dr = 100;
  110.     short    val;
  111.  
  112.  
  113.     prefsize(300L, 300L);
  114.  
  115.     winopen("cube");
  116.  
  117.     qdevice(KEYBD);
  118.     unqdevice(INPUTCHANGE);
  119.  
  120.     nplanes = getplanes();
  121.  
  122.     color(BLACK);
  123.     clear();
  124.  
  125.     window(-1.5, 1.5, -1.5, 1.5, 9.0, -5.0);
  126.     lookat(0.0, 0.0, 12.0, 0.0, 0.0, 0.0, 0.0);
  127.  
  128.     backface(1);
  129.  
  130.     if (argc == 1)
  131.         polymode(PYM_LINE);
  132.     
  133.     doublebuffer();
  134.     gconfig();
  135.  
  136.     t = 0.0;
  137.  
  138.     do {
  139.         for (r = 0; r < 3600; r += dr) {
  140.             color(BLACK);
  141.             clear();
  142.             pushmatrix();
  143.                 translate(0.0, 0.0, t);
  144.                 rotate(r, 'y');
  145.                 rotate(r, 'z');
  146.                 rotate(r, 'x');
  147.                 color(WHITE);
  148.                 drawcube();
  149.                 if (nplanes == 1 && argc > 1) {
  150.                     polymode(PYM_LINE);
  151.                     color(0);
  152.                     drawcube();
  153.                 }
  154.                 if (argc > 1)
  155.                     polymode(PYM_FILL);
  156.  
  157.             popmatrix();
  158.  
  159.             t += dt;
  160.             if (t > 3.0 || t < -18.0)
  161.                 dt = -dt;
  162.  
  163.             swapbuffers();
  164.  
  165.             if (qtest()) {
  166.                 if(qread(&val) == KEYBD) {
  167.                     gexit();
  168.                     exit(0);
  169.                 }
  170.             }
  171.         }
  172.     } while(1);
  173. }
  174.  
  175.